/**
 * 云汇卡列表
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="margin-t10">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>云汇卡列表</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="boxBlock">
      <div class="serachTop">
        <!-- 搜索筛选 -->
          <el-form :inline="true" :model="formInline" class="user-search">
            <el-form-item  >
              <el-input
                size="small"
                v-model="formInline.nickName"
                placeholder="输入昵称" 
                clearable
              ></el-input>
            </el-form-item>
             
            <el-form-item label="">
              <el-input
                size="small"
                v-model="formInline.cardNumber"
                placeholder="输入卡号后四位"
                type="number"
                clearable
              ></el-input>
            </el-form-item>

           <!-- <el-form-item prop="createdAtStart">
              <el-date-picker
                v-model="formInline.createdAtStart"
                type="date"
                size="small"
                placeholder="选择开始日期" 
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label=""> — </el-form-item>
            <el-form-item prop="createdAtEnd">
              <el-date-picker
                v-model="formInline.createdAtEnd"
                type="date"
                size="small"
                placeholder="选择结束日期"
              >
              </el-date-picker>
            </el-form-item>   -->
            <el-form-item>
              <el-button
                size="small"
                type="primary"
                icon="el-icon-search"
                @click="search"
                >搜索</el-button
              >
  
            </el-form-item>
          </el-form> 
      </div>
 
    
    <!--列表-->
    <div class="ra_box"> 
      <el-table
        size="small"
        :data="listData"
        highlight-current-row
        v-loading="loading"
        element-loading-text="拼命加载中"
        style="width: 100%"
        v-if="listData"
      >
        <el-table-column prop="nickName" label="昵称" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="cardNumber" label="卡号" show-overflow-tooltip min-width="220">
        </el-table-column> 
        <el-table-column
          prop="recordTime"
          label="创建时间"
          min-width="220"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            {{ timestampToTime(scope.row.recordTime) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="recordTime"
          label="完整卡号"
          min-width="220"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-input v-model="scope.row.cardNo"  size="small" placeholder="请输入完整卡号"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="recordTime"
          label="有效期"
          min-width="220"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-input v-model="scope.row.expirationDate" size="small" placeholder="请输入有效期"></el-input>
          </template>
        </el-table-column>

        <el-table-column
          prop="recordTime"
          label="cvv"
          min-width="220"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-input v-model="scope.row.cvv" size="small" placeholder="请输入cvv"></el-input>
          </template>
        </el-table-column>
        
        <!-- <el-table-column
          prop="createdAtStart"
          label="开始时间"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            {{ timestampToTime(scope.row.createdAtStart) }}
          </template>
        </el-table-column> -->
        <!-- <el-table-column
          prop="createdAtEnd"
          label="结束时间"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            {{ timestampToTime(scope.row.createdAtEnd) }}
          </template>
        </el-table-column> -->
         
        <el-table-column
          align="center"
          label="操作"
          width="150"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-button size="mini" type="primary"  @click="handleEdit(scope.row)">
              保存
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>

  </div>  
 
    <codeChoose ref="codeRef" :fromType="verType" @setParam="getParam" ></codeChoose>
  </div>
</template>

<script>
import { mapState, mapGetters } from "vuex";
import codeChoose from '@/components/codeChoose.vue'
import {
  setStoreS,
  getStoreS,
  removeStoreS,
  insertCharacter,
  timestampToTime,
  spStr,
  
} from "../../utils/util";
 
import { baseURL, service, format, getUrl,reqJson,    encrypt,  encryptp,  decryptp, } from "../../api/axiosFun";
import Pagination from "../../components/Pagination";
export default {
  data() {
    return {
      loading: false, 
      b: format,
      timestampToTime: timestampToTime, 
      editForm: {}, 
      formInline: {
        pageNum: 1,
        pageSize: 10, 
      },
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },
      headers:'',
      verArry:[],
      verType:'',
      curItem:'', 
      userInfo: null,
      fd:''
    };
  },
  // 注册组件
  components: {
    Pagination,
    codeChoose
  }, 
  computed: {
    ...mapGetters(["getUser"]),
  },
  watch: {
    getUser(newVal) {
      this.userInfo = JSON.parse(newVal);
    },
  },

  created() {
    this.getdata(this.formInline);
    this.getInfo();
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
 
    getdata(parameter) {
      let url = getUrl(parameter); 
      service
        .get("/api/admin/cardListAir" + url)
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.listData = res.rows;
            this.pageparm.currentPage = this.formInline.pageNum;
            this.pageparm.pageSize = this.formInline.pageSize;
            this.pageparm.total = res.total;
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.pageNum = parm.currentPage;
      this.formInline.pageSize = parm.pageSize;
      this.getdata(this.formInline);
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline);
    },
    //显示编辑界面
    handleEdit(row) { 
      // cardId expirationDate cvv 
      // row.cardNo+'.'+row.expirationDate+'.'+row.cvv
      if(!row.cardNo) return this.$message.error('请填写完整卡号');
      if(!row.expirationDate) return this.$message.error('请填写有效期');
      if(!row.cvv) return this.$message.error('请填写cvv');

      let url = getUrl(
        {
          cardId:row.cardId,
          sensitive: encrypt(row.cardNo+'.'+row.expirationDate+'.'+row.cvv) 
        }
      ); 
      reqJson('post',"/api/admin/setAirCardSensitive" + url,{
        cardId:row.cardId,
        sensitive: encrypt(row.cardNo+'.'+row.expirationDate+'.'+row.cvv) 
        // expirationDate:row.expirationDate,
        // cvv:row.cvv
      },{
        headers:{
          ...this.headers
        }
      }).then((res) => {
        if (res.code == 0) {
            this.$message.success("提交成功，请等待审核..."); 
            this.getdata(this.formInline);
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },

    getParam(val,type){  
      this.headers = val ;
      this.editSaveAuth() 
    },  
    
    getInfo() {
      service
        .get("/api/photon/getUserInfo", {})
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.userInfo = res.data;
            this.$store.commit("user", JSON.stringify(res.data));
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
 
 
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 